package com.wlr.study.task;

import com.wlr.task.SHP;

import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import javax.swing.WindowConstants;

public class TicTacToe_View extends JFrame {
    JButton[] gameButtons;
    JButton resetGame;
    JLabel label;
    // default constructor
    public TicTacToe_View() {
        initComponents();
        setLayout();
        setVisible(true);
        pack();
        setTitle("Tic Tac Toe");
        setDefaultCloseOperation(
                WindowConstants.EXIT_ON_CLOSE);
    }
    // create memory for the JButtons and JLabel
    public void initComponents() {
        gameButtons = new JButton[9];
        for (int i = 0; i < gameButtons.length; i++) {
            gameButtons[i] = new JButton();
        }
        resetGame = new JButton("Reset Game");
        label = new JLabel("X's turn");
    }
    // create a GridLayout to hold the 9 JButtons
    // use GroupLayout to organize the view
    // check the alignment of the components of the UI
    // in the question
    private void setLayout(){
        JPanel panel = new JPanel();
        panel.setSize(600, 600);
        GridLayout grid = new GridLayout(3, 3);
        panel.setLayout(grid);
        for (int i = 0; i < 9; i++)
            panel.add(gameButtons[i]);

        GroupLayout layout = new
                GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(true);
        layout.setHorizontalGroup(layout
                .createParallelGroup()
                .addComponent(label,
                        GroupLayout.Alignment.LEADING)
                .addComponent(panel,
                        GroupLayout.Alignment.CENTER)
                .addComponent(resetGame,
                        GroupLayout.Alignment.LEADING));
        layout.setVerticalGroup(layout
                .createSequentialGroup()
                .addComponent(label)
                .addComponent(panel)
                .addComponent(resetGame));
    }

    public void test() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<TicTacToe_View> ticTacToeViewClass = TicTacToe_View.class;
        ticTacToeViewClass.getDeclaredConstructor(SHP.class).newInstance(SHP.class);
    }
    public static void main(String[] arg) {

        String str="http://192.168.131.128:8080/Hotel/reserve/layui-v2.6.6/layui/css/layui.css";
        String wordToRemove = "reserve/";
        System.out.println(str.replaceAll("\\b" + wordToRemove + "\\b",""));
    }
}

